
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using DesignPatternDefinitions;
using System.Data;
using System.Collections;
using System.Windows.Forms;

namespace BusinessLayer
{
	/// <summary>
	/// class that implements IProject
	/// </summary>
	public class DPProject : IProject
	{
		private DataSet dataset;
		private DataRow projRow;
		public DPProject(DataSet ds)
		{
			this.dataset = ds;
			if( this.dataset.Tables[SchemaNames.Project].Rows.Count==0)
			{
				Console.WriteLine("No Project row found...self corecting.");
				return;
			}
			this.projRow =this.dataset.Tables[SchemaNames.Project].Rows[0];
		}
		#region IProject Members

		public string ProjectSummary {
			get {
				// TODO:  Add DPProject.ProjectSummary getter implementation
				if( projRow!=null)
				{
					if(this.projRow[SchemaNames.Summary] == null)
						this.projRow[SchemaNames.Summary] = string.Empty;

					return (string)this.projRow[SchemaNames.Summary];
				}
				else 
					return "Project Summary";
			}set{}
		}

		public string ProjectAuthor {
			get {
				if( projRow!=null)
				{
					if(this.projRow[SchemaNames.ProjectAuthor] == null)
						this.projRow[SchemaNames.ProjectAuthor] = string.Empty;
					return (string)this.projRow[SchemaNames.ProjectAuthor];
				}
				else
					return "Project Author";
			}set{}
		}

		public string ProjectName {
			get {
				if( projRow!=null)
				{
					if(this.projRow[SchemaNames.ProjectName] == null)
						this.projRow[SchemaNames.ProjectName]="NoNameProject";
					return (string)this.projRow[SchemaNames.ProjectName];
				}
				else
					return "NoNameProject";
			}set{}
		}

		public System.Collections.ArrayList Components {
			get {
				ArrayList ComponentsList =  new ArrayList();
				DataTable ComponentTable = this.dataset.Tables[SchemaNames.Components];
				DataRow []Crows =  ComponentTable.Select();

				foreach(DataRow row in Crows) 
					ComponentsList.Add(new DPComponent(row));	

				return ComponentsList;
			}set{}
		}

		public IClass GetClass(string componentName,string className)
		{
			return this.GetComponent(componentName).GetClass(className);
		}
		public IProjectComponent GetComponent(string componentName)
		{
			DataTable compTable = this.dataset.Tables[SchemaNames.Components];
			DataRow row = compTable.Rows.Find(componentName);
			if(row==null)
			{
				Console.WriteLine("In IProjectComponent.GetComponent():Error for component:"+componentName);
				return null;
			}
			return new DPComponent(row);
		}

		#endregion
	}
}
